package pt.inescid.components.policyengine.heimdall.pdp.base;

import pt.inescid.components.policyengine.heimdall.pap.base.RuleDefinition;
import pt.inescid.components.policyengine.heimdall.pap.base.SimpleDefinition;

public class SimpleInstance extends RuleInstance {

	private SimpleDefinition definition = null;
	protected Object value = null;

	//  ----------------------------------------------------------
//  ------------------------   constructor   ------------------------
//  ----------------------------------------------------------
	public SimpleInstance(SimpleDefinition definition,
			PolicyInstance currentPolicy) {
		super(definition);
		this.definition = definition;
	}


//  ----------------------------------------------------------
//  ------------------------   evaluate   ------------------------
//  ----------------------------------------------------------
	public Object evaluate(ModelInstance currentModel, boolean onlyCached) {
		if (value != null) {
			return (value);
		}
		
		switch (definition.getValueType()) {
		case RuleDefinition.STRING_VALUE:
			return (definition.getValue());
		case RuleDefinition.INT_VALUE:
			return (new Integer(definition.getValue()));
		case RuleDefinition.LONG_VALUE:
		case RuleDefinition.TIMESTAMP_VALUE:
			return (new Long(definition.getValue()));
		case RuleDefinition.BOOLEAN_VALUE:
			return (new Boolean(definition.getValue()));

		default:
			break;
		}
		
		return (null);
	} // evaluate

//  ----------------------------------------------------------
//  ------------------------   toString   ------------------------
//  ----------------------------------------------------------
	public String toString() {
		return (super.toString());
	}

}; // SimpleExpression
